#include "pch.h"
#include <stdio.h>

char toString(int bit)
{
	char c;
	if (bit >= 10)
		c = bit + 55;
	else
		c = bit + 48;
	return c;
}

char* toOthSystem(int num, int system)
{
	char *result = new char[100];
	int nowsub = 0;
	do
	{
		int bit = num % system;
		result[nowsub] = toString(bit);
		nowsub++;
		num /= system;
	} while (num != 0);

	char *rresult = new char[nowsub + 1];
	for (int i = 0;i < nowsub;i++)
	{
		rresult[i] = result[nowsub - 1 - i];
	}

	rresult[nowsub] = '\0';
	delete[]result;

	return rresult;
}

int main()
{
	printf("请输入待转换的数字：");
	int num;
	scanf_s("%d", &num);
	printf("请输入要转换到的进制：");
	int system2;
	scanf_s("%d", &system2);
	printf("%s", toOthSystem(num, system2));
}